package Niuke;

import java.util.Scanner;
public class tt {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int i = in.nextInt();
        for (int j=1;j<=i;j++){
            int n,m,a,b;
            n=in.nextInt();
            m=in.nextInt();
            a=in.nextInt();
            b=in.nextInt();
            int[] ability=new int[a];
            for (int ii=0;ii<a;ii++){
                ability[ii]=in.nextInt();
            }
            char[][] chars=new char[n][m];
            for (int q=0;q<n;q++){
                String next = in.next();
                char[] chars1 = next.toCharArray();
                for (int w=0;w<m;w++){
                    chars[q][w]=chars1[w];
                }
            }
            dis(chars,a,b,ability);

        }
    }
    public static void dis(char[][] chars,int a,int b,int[] ability){
        if (a<b) System.out.println("-1");

    }
}
